<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

require_once $controller->working_dir . 'inc/Setting.php';
require_once $controller->working_dir . 'inc/SettingModel.php';


// initialize objects
$rq =& new RequestData($_GET);
$rp =& new RequestData($_POST);
$rp->wordrap_num = 300;


$obj = new Setting;

$manager =& $obj->setManager(new SettingModel());
$manager->checkPriv($priv, $controller->action, @$rq->id);


$setting_ar = array('kb_setting'	=> 'knowledgebase',
                    'file_setting'	=> 'file',
					'email_setting'	=> 'email_setting');
$manager->setModuleId($setting_ar[$controller->page]);


if(isset($rp->submit)) {
	
	if(APP_DEMO_MODE) { $controller->go('not_allowed_demo', true); }

	$parser = $manager->getParser();
	$rp->values = $parser->parseReplacementsArray($manager->formDataToObj($rp->values));
	
	$is_error =& $obj->validate($rp->values, $manager);	
	
	if($is_error) {
		$rp->stripVars(true);
		$obj->set($rp->values);
		
	} else {
		$rp->stripVars();
		$manager->save($rp->values);
		
		$controller->go();
	}

} elseif(isset($rp->set_default)) {
		
		if(APP_DEMO_MODE) { $controller->go('not_allowed_demo', true); }		
		
		$manager->setDefaultValues();
		$controller->go();

} else {
	
	$data = &$manager->getSettings();
	$rp->stripVarsValues($data);
	$obj->set($data);
}


$view = &$controller->getView($obj, $manager, 'SettingView_form');
?>